//
//  MtabBarController.swift
//  iOSweibo
//
//  Created by lzm on 16/5/10.
//  Copyright © 2016年 lzm. All rights reserved.
//

import UIKit

class MtabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //1.定义闭包弹出控制器
        let composeCallBack = {() -> () in
            print("弹出控制器~")
            
        }
        let mainTabBar = MMainTabBar()
        //2.传递闭包
        setValue(mainTabBar, forKey: "tabBar")
        mainTabBar.composeCallBack = composeCallBack
        setup()
    }
    
    func setup()
    {
//        let homeVC = MHomeViewController()
//        homeVC.title = "首页"
//        homeVC.tabBarItem.image = UIImage(imageLiteral: "tabbar_home")
//        homeVC.tabBarItem.selectedImage = UIImage(imageLiteral: "tabbar_home_selected")
//        self.addChildViewController((UINavigationController(rootViewController: homeVC)))
//        
//        let MessageVC = MMessageViewController()
//        MessageVC.title = "消息"
//        MessageVC.tabBarItem.image = UIImage(imageLiteral: "tabbar_message_center")
//        MessageVC.tabBarItem.selectedImage = UIImage(imageLiteral: "tabbar_message_center_selected")
//        self.addChildViewController((UINavigationController(rootViewController: MessageVC)))
//        
//        let DiscoveryVC = MDicoveryViewController()
//        DiscoveryVC.title = "发现"
//        DiscoveryVC.tabBarItem.image = UIImage(imageLiteral: "tabbar_discover")
//        DiscoveryVC.tabBarItem.selectedImage = UIImage(imageLiteral: "tabbar_discover_selected")
//        self.addChildViewController((UINavigationController(rootViewController: DiscoveryVC)))
//        
//        
//        
//        let MeVC = MMeViewController()
//        MeVC.title = "我"
//        MeVC.tabBarItem.image = UIImage(imageLiteral: "tabbar_profile")
//        MeVC.tabBarItem.selectedImage = UIImage(imageLiteral: "tabbar_profile_selected")
//        self.addChildViewController((UINavigationController(rootViewController: MeVC)))
        //设置主页
        self.addChildViewController(MHomeViewController(), title: "主页", image:  "tabbar_home")
        //设置消息
        self.addChildViewController(MMessageViewController(), title: "消息", image:  "tabbar_message_center")
        //设置主页
        self.addChildViewController(MDicoveryViewController(), title: "发现", image:  "tabbar_discover")
        //设置主页
        self.addChildViewController(MMeViewController(), title: "我", image:  "tabbar_profile")
    }
    
    func addChildViewController(childController: UIViewController,title : String,image : String) {
        let VC = childController
        VC.title = title
        VC.tabBarItem.image = UIImage(named: image)
        VC.tabBarItem.selectedImage = UIImage(named: image+"_selected")
        
        VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        addChildViewController((UINavigationController(rootViewController: VC)))
        
    }

}
